package ym.controller.front.repair;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ym.pojo.RepairAppeal;
import ym.service.RepairAppealService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 维修申诉
 */
@RestController
@CrossOrigin
    @RequestMapping("/front/repairAppeal")
public class FrontRepairAppealController {
    @Autowired
    private RepairAppealService repairAppealService;

    /**
     * 新增
     *
     * @param repairAppeal
     * @return
     */
    @PostMapping("/add")
    public BaseResult add(RepairAppeal repairAppeal) {
        repairAppealService.add(repairAppeal);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param repairAppeal
     * @return
     */
    @PostMapping("/update")
    public BaseResult update(RepairAppeal repairAppeal) {
        repairAppealService.update(repairAppeal);
        return BaseResult.ok();
    }

    /**
     * 删除
     *
     * @param repairAppealId
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Integer repairAppealId) {
        repairAppealService.delete(repairAppealId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询
     *
     * @param repairAppealId
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer repairAppealId) {
        RepairAppeal repairAppeal = repairAppealService.findById(repairAppealId);
        return BaseResult.ok(repairAppeal);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    public BaseResult findAll() {
        List<RepairAppeal> repairAppeals = repairAppealService.findAll();
        return BaseResult.ok(repairAppeals);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search")
    public BaseResult search(String search, int page, int size) {
        Page<RepairAppeal> repairAppealPage = repairAppealService.search(search, page, size);
        return BaseResult.ok(repairAppealPage);
    }

    /**
     * 根据维修报备id查询
     *
     * @param repairReportId
     * @param search
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/searchByRepairReportId")
    public BaseResult searchByRepairReportId(Integer repairReportId, String search, int page, int size) {
        Page<RepairAppeal> repairAppealPage = repairAppealService.searchByRepairReportId(repairReportId, search, page, size);
        return BaseResult.ok(repairAppealPage);
    }
}
